﻿using System;
using System.Windows.Forms;
namespace TwinHead.Frameworks.WindowForms
{
    /// <summary>
    /// 폼이나, 컨트롤에서 기다림 커서사용을 도와줍니다.
    /// </summary>
    public sealed class WaitCursor : IDisposable
    {
        private bool isDisposed = false;

        private Form f;
        private Control c;

        /// <summary>
        /// 폼에 대응하는 기본생성자입니다.
        /// </summary>
        /// <param name="f"></param>
        public WaitCursor( Form f )
        {
            this.f = f;
            this.f.Cursor = Cursors.WaitCursor;
        }

        /// <summary>
        /// 콘트롤에 대응하는 기본생성자입니다.
        /// </summary>
        /// <param name="c"></param>
        public WaitCursor( Control c )
        {
            this.c = c;
            this.c.Cursor = Cursors.WaitCursor;
        }

        /// <summary>
        /// 사용중인 자원을 모두 해제합니다
        /// </summary>
        public void Dispose()
        {
            Dispose( this.isDisposed );
        }

        private void Dispose( bool isDisposed )
        {
            if (!isDisposed)
            {
                if (f != null)
                    this.f.Cursor = Cursors.Default;

                if (c != null)
                    this.c.Cursor = Cursors.Default;
            }

            this.isDisposed = true;
        }
    }
}
